/**
 * Copyright 2006-2015 handu.com
 * <p/>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p/>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p/>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.iepacj.common.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 日期相关工具类
 * @author iEpacJ
 */
public class DateUtils {

    private static final String DEFAULT_DATE_FORMAT_PATTERN = "yyyy-mm-dd HH:MM:ss";

    /**
     * 以默认模式格式化当前日期
     * @return  返回当前日期 2016-08-18 14:20:00
     */
    public static String format() {
        return format(new Date(), DEFAULT_DATE_FORMAT_PATTERN);
    }

    /**
     * 以默认模式格式化指定日期
     * @return  返回日期 2016-08-18 14:20:00
     */
    public static String format(Date date) {
        return format(date, DEFAULT_DATE_FORMAT_PATTERN);
    }

    /**
     * 格式化日期
     * @return  返回日期 2016-08-18 14:20:00
     */
    public static String format(Date date, String pattern) {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        return sdf.format(date);
    }

    /**
     * 当前时间 往前或者往后的几天
     * @param timeOfDay 天数 负数: 当前时间之前  正数: 之后
     */
    public static Date getPreviousOrAfterTimeOfDay(int timeOfDay) {
        Calendar currCale = Calendar.getInstance();
        currCale.set(Calendar.DAY_OF_MONTH, currCale.get(Calendar.DAY_OF_MONTH) + timeOfDay);
        return currCale.getTime();
    }




}







